package com.zerdoor.service.impl;

import com.zerdoor.dao.RbacManagerDao;
import com.zerdoor.service.RbacManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by xiaoji on 2015/2/2.
 */
@Service
public class RbacManagerServiceImpl implements RbacManagerService{
    @Autowired
    private RbacManagerDao rbacManagerDao;

    /**
     * 查看所有管理员
     *
     * @param map 查询条件
     * @return
     */
    @Override
    public List<Map<String, Object>> getRbacManagers(Map<String, Object> map) {
        return rbacManagerDao.getRbacManagers(map);
    }

    /**
     * 查询登陆账号是否唯一
     *
     * @param loginName
     * @return
     */
    @Override
    public boolean getTotalByLoginName(String loginName) {
        Map<String, Object> map = rbacManagerDao.getTotalByLoginName(loginName);
        if(map != null && Integer.parseInt(map.get("total").toString()) == 0){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 添加管理员
     *
     * @param map 管理员信息
     */
    @Override
    public void addRbacManagers(Map<String, Object> map) throws Exception {
        rbacManagerDao.addRbacManagers(map);
    }

    /**
     * 编辑管理员
     *
     * @param map 管理员基本信息
     * @throws Exception
     */
    @Override
    public void updateRbacManagers(Map<String, Object> map) throws Exception {
        rbacManagerDao.updateRbacManagers(map);
    }

    /**
     * 停用管理员
     *
     * @param map 管理员信息
     * @throws Exception
     */
    @Override
    public void updateStopRbacManagers(Map<String, Object> map) throws Exception {
        rbacManagerDao.updateStopRbacManagers(map);
    }

    /**
     * 激活管理员
     *
     * @param map
     * @throws Exception
     */
    @Override
    public void updateActivationRbacManagers(Map<String, Object> map) throws Exception {
        rbacManagerDao.updateActivationRbacManagers(map);
    }

    /**
     * 删除管理员
     *
     * @param userId 管理员编号
     * @throws Exception
     */
    @Override
    public void deleteRbacManagers(int userId) throws Exception {
        rbacManagerDao.deleteRbacManagers(userId);
    }

    /**
     * 获取所有有效角色列表
     *
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> getRbacRoles() {
        return rbacManagerDao.getRbacRoles();
    }
}
